#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
A module for calculating intensity of a givven belt on a givven grid
'''


from plane import Plane
from grid_plane import PlaneGrid

def calculate_intensity(grid, pplane):
    pplane = Plane(int(pplane.dir), int(pplane.dip))
    intensity = 0
    for angle in range (0,180,1):
        a = pplane.rotated(angle)
        intensity += grid.get(plane=Plane(int(a.dir), abs(90-int(a.dip))))
    return intensity

def building_grid_of_intensity(grid, increment):
    # Build a grid of intensity
    #dirsize = int(360.0/increment) # размер элементарной ячейки 
    #dipsize = int(90.0/increment)
    belt_axes = PlaneGrid(incr=[increment, increment])
    mval=0.0
    for dir in range(0, 360, increment):
        for dip in range(0, 90, increment):
            pplane = Plane(dir, dip)
            intencity = calculate_intensity(grid, pplane)
            belt_axes.set(plane=pplane, val=intencity)
            mval = max([intencity, mval])
    return belt_axes, mval
